<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="test.css">

<script type="text/javascript" src="test_runner.js"></script>

<title>Test demo</title>
</head>
<body>
	<div id="testResult" style="float: left;"></div>
	<div id="countDiv"
		style="float: right; border: 1px solid grey; padding-left: 2px; padding-right: 2px;">
		<span>SetupBeforeClass called <span
			id='setupBeforeClassCounter'>0</span> times.
		</span><br /> <span>Setup called <span id='setupCounter'>0</span>
			times.
		</span><br /> <span>TearDown called <span id='tearDownCounter'>0</span>
			times.
		</span><br /> <span>TearAfterClass called <span
			id='tearAfterClassCounter'>0</span> times.
		</span><br />
	</div>

	<!-- TestCase example -->
	<script type="text/javascript">
		Assert.staticImport();

		var countSetup = 0;
		var countSetupBeforeClass = 0;
		var countTearDown = 0;
		var countTearAfterClass = 0;

		var testCase = {};

		testCase.getTestCaseName = function() {
			return "Test Case Demo";
		};

		testCase.setUpBeforeClass = function() {
			countSetupBeforeClass++;
			document.getElementById('setupBeforeClassCounter').innerHTML = countSetupBeforeClass;
		};

		testCase.tearDownAfterClass = function() {
			countTearAfterClass++;
			document.getElementById('tearAfterClassCounter').innerHTML = countTearAfterClass;
		};

		testCase.setUp = function() {
			countSetup++;
			document.getElementById('setupCounter').innerHTML = countSetup;
		};

		testCase.tearDown = function() {
			countTearDown++;
			document.getElementById('tearDownCounter').innerHTML = countTearDown;
		};

		testCase.testOK = function() {
		};

		testCase.testFail = function() {
			Assert.fail("Test fail(...) method.");
		};

		testCase.testAssertEqualsOK = function() {
			Assert.assertEquals("2", 2, "This message must not be shown.");
		};

		testCase.testAssertEqualsFailure = function() {
			Assert.assertEquals("value", "different value", "Test assertEquals(...) failure.");
		};

		testCase.testAssertSameOK = function() {
			var value = {};
			Assert.assertSame(value, value, "This message must not be shown.");
		};

		testCase.testAssertSameFailure = function() {
			Assert.assertSame("1", 1, "Test assertSame(...) failure.");
		};

		testCase.testAssertNotSameOK = function() {
			Assert.assertNotSame("1", 1, "This message must not be shown.");
		};

		testCase.testAssertNotSameFailure = function() {
			Assert.assertNotSame("1", "1", "Test assertNotSame(...) failure.");
		};

		testCase.testAssertNullOK = function() {
			Assert.assertNull(null, "This message must not be shown.");
		};

		testCase.testAssertNullFailure = function() {
			Assert.assertNull({}, "Test assertNull(...) failure");
		};

		testCase.testAssertNotNullOK = function() {
			Assert.assertNotNull({}, "This message must not be shown.");
		};

		testCase.testAssertNotNullFailure = function() {
			Assert.assertNotNull(null, "Test assertNotNull(...) failure");
		};

		testCase.testAssertTrueOK = function() {
			Assert.assertTrue(true, "This message must not be shown.");
		};

		testCase.testAssertTrueFailure = function() {
			Assert.assertTrue(false, "Test assertTrue(...) failure.");
		};

		testCase.testAssertFalseOK = function() {
			Assert.assertFalse(false, "This message must not be shown.");
		};

		testCase.testAssertFalseFailure = function() {
			Assert.assertFalse(true, "Test assertTrue(...) failure.");
		};

		testCase.testAssertArrayEquals = function() {
			Assert.assertArrayEquals([ "val1", "val2" ], [ "val1", "val2" ], "This message must not be shown.");
		};

		testCase.testAssertArrayEqualsFailure = function() {
			Assert.assertArrayEquals([ "val1", "val2" ], [ "val1", "differentVal" ], "Test assertArrayEquals(...) failure.");
		};

		testCase.testStaticImportOK = function() {
			assertTrue(true, "This message must not be shown.");
		};

		testCase.testUnexpectedError = function() {
			throw "Unexpected Error in the test case.";
		};

		new TestRunner(testCase).run();
	</script>


	<!-- TestSuite example -->
	<script type="text/javascript">
		var testCase1 = {};
		testCase1.test = function() {
		};

		var testCase2 = {};
		testCase2.test = function() {
			Assert.fail("Failing test");
		};
		
		var testCase3 = {};
		testCase3.test = function() {
		};

		new TestSuite(testCase1, [testCase2, testCase3]).run();
	</script>

	<!-- Asynchronous testing example -->
	<script type="text/javascript">
		var testCaseAsynch = {};

		testCaseAsynch.test = function(assert, manager) {
			setTimeout(function() {
				manager.finishTest()
			}, 100);

			manager.setTimeOut(1000);
		};

		testCaseAsynch.testTimeOut = function(assert, manager) {
			setTimeout(function() {
				manager.finishTest();
			}, 1000);

			manager.setTimeOut(500);
		};

		testCaseAsynch.testNoTimeOut = function(assert, manager) {
			setTimeout(function() {
				manager.finishTest()
			}, 1000);
		};

		new AsynchTestRunner(testCaseAsynch).run();
	</script>

</body>
</html>